package com.auleev.string;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;



public class PatternUtil {

  
  
  private static final Pattern EMAIL_PATTERN = Pattern.compile("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
  private static final Pattern FIRSTNAME_LASTNAME_PATTERN = Pattern.compile("^(.+)\\s+(.+)$");
  
  
  
  public static String[] extractFirstNameAndLastName(final String firstNameAndLastName) {
    Matcher matcher = FIRSTNAME_LASTNAME_PATTERN.matcher(StringUtils.trimToEmpty(firstNameAndLastName));
    if (matcher.matches() && matcher.groupCount() == 2) {
      return new String[] { matcher.group(1), matcher.group(2) };
    }
    return null;
  }

  /**
   * private constructor to avoid useless instantiation
   */
  private PatternUtil() {
    // private constructor to avoid useless instantiation
  }
}
